package com.wsc.frontier;

import java.io.File;
import java.io.FileNotFoundException;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;

public class FrontierDetails {
	static String server_doc_root,mysql_path,received_urls_dir,server_ip;
	static int port;
	static XMLConfiguration config = null;
	
	public static void loadXmlFile() throws FileNotFoundException {
		File f;
		f = new File("config/frontier-properties.xml");
		try {
			if(f.exists())
			config = new XMLConfiguration(f);

			// config.load();
		} catch (ConfigurationException e) {
			//e.printStackTrace();
		}
		// set expression engine to exexute xpath queries on config.xml file

		config.setExpressionEngine(new XPathExpressionEngine());
	}
	
	public static void getAllDetails(){
		
	 
		server_doc_root = (String) config
				.getProperty("/property/entry[@name='Frontier-Server-Doc-Root']");
		
		port = Integer.parseInt((String) config
				.getProperty("/property/entry[@name='Frontier-Server-Port']"));
		
		mysql_path = (String) config
				.getProperty("/property/entry[@name='Mysql-Path']");
		
		received_urls_dir = (String) config
				.getProperty("/property/entry[@name='Received-URLs-Dir']");
		
		server_ip = (String) config
				.getProperty("/property/entry[@name='Frontier-Server-IP']");
	}
	
	public static String getServerIP() {
		return server_ip;
	}

	
	public static String getServerRootDirectory() {
		return server_doc_root;
	}
	
	public static int getFrontierServerPort() {
		return port;
	}
	
	public static String getMysqlPath() {
		return mysql_path;
	}
	
	public static String getReceivedURLsDir(){
		return received_urls_dir;
	}

	public static void main(String...s) throws FileNotFoundException{
		
		FrontierDetails.loadXmlFile();
		System.out.println(FrontierDetails.getServerIP());
		
	}
	
}
